<template>
  <div class="mod-menu">
    <el-form :inline="true" :model="dataForm" @keyup.enter.native="getDataList()" class="search_container">
      <el-form-item label="险种代码">
        <el-input v-model="dataForm.crtable" placeholder="险种代码" clearable></el-input>
      </el-form-item>
      <el-form-item>
        <el-button @click="getDataList()">查询</el-button>
      </el-form-item>
    </el-form>

    <div class="contain">
      <!-- 操作按钮 -->
      <el-row>
        <el-col :span="24" class="pb15 pt5">
          <el-button type="info" plain size="mini" style="margin-left: 10px;" @click="addOrUpdateHandle()">新增</el-button>
        </el-col>
      </el-row>

      <!-- 查询结果列表 -->
      <div class="table_container">
        <!-- 列表 -->
        <el-table
          :data="dataList"
          border
          style="width: 100%; ">
          <el-table-column type="expand">
            <template slot-scope="scope">
              <el-table
                :data="scope.row.list"
                style="width: 100%">
                <el-table-column
                  type="index"
                  width="50">
                </el-table-column>
                <el-table-column
                  property="startTime"
                  label="版本起期">
                </el-table-column>
                <el-table-column
                  property="cltdobCon"
                  :formatter="formatterCltdobCon"
                  label="出险年龄条件">
                </el-table-column>
                <el-table-column
                  property="clmType"
                  :formatter="formatterClmType"
                  label="理赔形态">
                </el-table-column>
                <el-table-column
                  property="acdtDteCon"
                  :formatter="formatterAcdtDteCon"
                  label="意外事故日">
                </el-table-column>
                <el-table-column
                  property="earlyHsDte"
                  :formatter="formatterEarlyHsDte"
                  label="入院日期是否为空">
                </el-table-column>
                <el-table-column
                  property="eventDate"
                  :formatter="formatterEventDate"
                  label="事故认定日">
                </el-table-column>
              </el-table>
            </template>
          </el-table-column>
          <el-table-column
            prop="crtable"
            header-align="center"
            align="center"
            label="险种代码">
          </el-table-column>

          <el-table-column
            header-align="center"
            align="center"
            width="150"
            label="操作">
            <template slot-scope="scope">
              <el-button v-if="isAuth('sys:menu:update')" type="text" size="small"
                         @click="addOrUpdateHandle(scope.row.crtable)">修改
              </el-button>
              <el-button v-if="isAuth('sys:menu:delete')" type="text" size="small" @click="deleteHandle(scope.row.crtable)">
                删除
              </el-button>
            </template>
          </el-table-column>
        </el-table>
        <!-- 分页 -->
        <el-row>
          <el-col :span="24">
            <div class="pagination">
              <!-- 分页 -->
              <el-pagination
                @size-change="sizeChangeHandle"
                @current-change="currentChangeHandle"
                :current-page="page.pageIndex"
                :page-sizes="[10, 20, 50, 100]"
                :page-size="page.pageSize"
                :total="page.totalPage"
                layout="total, sizes, prev, pager, next, jumper">
              </el-pagination>
            </div>
          </el-col>
        </el-row>
      </div>
    </div>





    <!-- 弹窗, 新增 / 修改 -->
    <add-or-update v-if="addOrUpdateVisible" ref="addOrUpdate" @refreshDataList="getDataList"></add-or-update>
  </div>
</template>

<script>
  import {pageList, del} from '@/api/eventdate'
  import AddOrUpdate from './add-or-update'
  import getLabel from '@/api/constant'
  import constant from '@/api/constant'

  export default {
    data() {
      return {
        dataForm: {
          crtable: ''
        },
        dataList: [],
        constant: constant,
        dataListLoading: false,
        addOrUpdateVisible: false,
        addActionVisible: false,
        addConditionVisible: false,
        page: {
          pageIndex: 1,
          pageSize: 10,
          totalPage: 0
        }
      }
    },
    components: {
      AddOrUpdate
    },
    activated() {
      this.getDataList()
    },
    methods: {
      formatterCltdobCon(row, column, cellValue, index) {
        return this.getLabel(row.cltdobCon, this.constant.eventDate.cltdobConProperties)
      },
      formatterClmType(row, column, cellValue, index) {
        return this.getLabel(row.clmType, this.constant.eventDate.claimTypeProperties)
      },
      formatterAcdtDteCon(row, column, cellValue, index) {
        return this.getLabel(row.acdtDteCon, this.constant.eventDate.acdtDteConProperties)
      },
      formatterEarlyHsDte(row, column, cellValue, index) {
        return this.getLabel(row.earlyHsDte, this.constant.eventDate.earlyHsDteProperties)
      },
      formatterEventDate(row, column, cellValue, index) {
        return this.getLabel(row.eventDate, this.constant.eventDate.eventDateProperties)
      },
      getLabel(value, properties) {
        let label = '';
        for (let item of properties) {
          if (item.value === value) {
            return item.label
          }
        }
        return label
      },
      // 每页数
      sizeChangeHandle(val) {
        this.page.pageSize = val
        this.page.pageIndex = 1
        this.getDataList()
      },
      // 当前页
      currentChangeHandle(val) {
        this.page.pageIndex = val
        this.getDataList()
      },

      // 获取数据列表
      getDataList() {
        this.dataListLoading = true
        let params = {
          pageNumber: this.page.pageIndex,
          pageSize: this.page.pageSize,
          crtable: this.dataForm.crtable
        }
        pageList(params).then(res => {
          this.dataListLoading = false
          this.dataList = res.data.data.list
          this.page.totalPage = res.data.data.totalCount
        })
      },
      // 新增 / 修改
      addOrUpdateHandle(crtable) {
        this.addOrUpdateVisible = true
        this.$nextTick(() => {
          this.$refs.addOrUpdate.init(crtable)
        })
      },

      // 删除
      deleteHandle(crtable) {
        this.$confirm(`确定对[险种=${crtable}]进行[删除]操作?`, '提示', {
          confirmButtonText: '确定',
          cancelButtonText: '取消',
          type: 'warning'
        }).then(() => {
          let params = {
            crtable: crtable + ''
          }
          del(params).then(res => {
            if (res.data && res.data.resultCode === 0) {
              this.$message({
                message: '操作成功',
                type: 'success',
                duration: 1500,
                onClose: () => {
                  this.getDataList()
                }
              })
            } else {
              this.$message.error(res.data.resultMsg)
            }
          })
        }).catch(() => {
        })
      },
    }

  }
</script>
<style>
  body .el-table th.gutter {
    display: table-cell !important
  }
</style>
